package com.gxh.controller.admin;

import com.gxh.dto.UserPageQueryDTO;
import com.gxh.entity.User;
import com.gxh.result.PageResult;
import com.gxh.result.Result;
import com.gxh.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin/user")
@Slf4j
@Api(tags = "管理端用户接口")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 用户分页查询
     * @param userPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("用户分页查询")
    public Result<PageResult> page(UserPageQueryDTO userPageQueryDTO){
        log.info("用户分页查询：{}", userPageQueryDTO);
        PageResult pageResult = userService.page(userPageQueryDTO);
        return Result.success(pageResult);
    }


    @GetMapping("/{id}")
    @ApiOperation("用户详情")
    public Result<User> getById(@PathVariable Long id){
        log.info("用户详情{}" ,id);
        User user = userService.getByUserId(id);
        return Result.success(user);
    }

}
